/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"FA74E30A-7C19-4F32-B3C3-BD78878B38B2"}
 */
var fPass = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"E1AFB6AE-3DDE-4DF3-9CF0-94C906E7F870"}
 */
var fPass2 = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"8D386988-683D-40AF-82CD-316F1EB7C2DA"}
 * @AllowToRunInFind
 */
function grabar(event) {
	if (usuario != null && mail_login != null && fPass != null && fPass2 != null)
	
	/** @type {JSFoundSet<db:/fwk_navigation_infocom/usuarios>} */
	var fs = databaseManager.getFoundSet('fwk_navigation_infocom','usuarios')

	fs.find()
		fs.usuario = usuario
	fs.newRecord()
		fs.mail_login = mail_login
	var cant = fs.search()
	
	if (cant == 1)
		globals.gDialog('Error','Ya existe un usuario con ese alias o direccion de e-mail','OK','CerrarForm')
	else
	{
		if (fPass == fPass2)
		{
			hash_pass 	= globals.hashPass(fPass)
			fPass 		= null
			fPass2 		= null
			databaseManager.saveData()
			databaseManager.setAutoSave(true)
			globals.show('productos_filtros')
			globals.gDialog('Exito','Usuario creado exitosamente','OK','CerrarForm')
		}
		else
		{
			fPass 	= null
			fPass2 	= null
			globals.gDialog('Error','Verificacion de contraseña fallo','OK','CerrarForm')
		}	
	}
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"DD122C7B-89AB-4F5E-B91F-94B7F115891D"}
 */
function onShowForm(firstShow, event) {
	databaseManager.setAutoSave(false)
	controller.newRecord()
	userv_id 	= globals.gUservId
	fPass 		= null
	fPass2 		= null
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"8E2F1900-C2C1-4DF9-ABA7-8EFE417BEAE7"}
 */
function cancelar(event) {
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	globals.show('productos_tbl')
}
